package cn.edu.zsc.blms.service.collection;

import cn.edu.zsc.blms.App;
import cn.edu.zsc.blms.domain.BaseEntity;
import cn.edu.zsc.blms.exception.EntityNotExistException;

import java.util.*;

public abstract class BaseService <T extends BaseEntity> {
    protected final Map<Integer, T> DATA = new TreeMap<>();
    protected T getEntity() throws EntityNotExistException{
        T entity;
        try{
            int id = Integer.parseInt(App.input.nextLine());
            if(!DATA.containsKey(id)){
                throw new EntityNotExistException();
            }
            entity = DATA.get(id);
        }catch (NumberFormatException e){
            throw new EntityNotExistException("ID为整数, 请输入整数值");
        }
        return entity;
    }
}
